﻿mui.init({
	swipeBack:false, //启用右滑关闭功能
	keyEventBind: {
		backbutton: true  //关闭back按键监听
	}
}); 
var userid;
mui.plusReady(initSomething);
function initSomething(){
	getBanner();
	getImportantNews();
	//监听手机返回按键
	common.utils.confirmLoginOut();
    //获取用户id
	userid = common.utils.getUserId();
	//获取用户组织类型
	var orgtype = common.utils.getOrgType();
//	var orgtype = "#root";//测试用
	//判断是否登陆
    common.utils.iflogin(userid);
    $("#nowHappen").on("tap",function(){//全程纪实
    	var orgid = common.utils.getOrgId();
		var nowHappen = plus.webview.create("../nowSee/nowSee.html", "../nowSee/nowSee.html", {scrollIndicator:'none'},{pid:orgid,name:"全程纪实"});
		plus.webview.show(nowHappen, "slide-in-right", "350ms", function() {}, false);
	});
	$("#orgBuild").on("tap",function(){//组织建设
		if(orgtype=='#root'){//总区域党委
			var orgBuild = plus.webview.create("../orgBuild/orgBuild.html", "../orgBuild/orgBuild.html", {scrollIndicator:'none'},{});
			plus.webview.show(orgBuild, "slide-in-right", "350ms", function() {}, false);
		}else if(orgtype=='1'){//党委
			var orgname = common.utils.getOrgName();
			var orgid = common.utils.getOrgId();
			var orgBuild = plus.webview.create("../orgBuild/org1Build.html", "../orgBuild/org1Build.html", {scrollIndicator:'none'},{orgname:orgname,orgid:orgid});
			plus.webview.show(orgBuild, "slide-in-right", "350ms", function() {}, false);
		}else{//党支部
			var orgBuild = plus.webview.create("../orgBuild/org2Build.html", "../orgBuild/org2Build.html", {scrollIndicator:'none'},{});
			plus.webview.show(orgBuild, "slide-in-right", "350ms", function() {}, false);
		}
	});
	$("#bigNews").on("tap",function(){//大事件
		var bigNews = plus.webview.create("../content/bigEvent.html", "../content/bigEvent.html", {scrollIndicator:'none'},{});
		plus.webview.show(bigNews, "slide-in-right", "350ms", function() {}, false);
	});
	$("#publicRead").on("tap",function(){//政策解读
		var publicRead = plus.webview.create("../content/policy.html", "../content/policy.html", {scrollIndicator:'none'},{type:'2',title:'政策解读'});
		plus.webview.show(publicRead, "slide-in-right", "350ms", function() {}, false);
	});
	$("#notice").on("tap",function(){//通知公告
		var notice = plus.webview.create("../notice/notice.html", "../notice/notice.html", {scrollIndicator:'none'},{type:'child'});
		plus.webview.show(notice, "slide-in-right", "350ms", function() {}, false);
	});
	$("#specialNews").on("tap",function(){//专题专栏
		var specialNews = plus.webview.create("../content/special.html", "../content/special.html", {scrollIndicator:'none'},{});
		plus.webview.show(specialNews, "slide-in-right", "350ms", function() {}, false);
	});
	$("#helpNews").on("tap",function(){//帮扶认领
		var helpNews = plus.webview.create("../content/policy.html", "../content/policy.html", {scrollIndicator:'none'},{type:'4',title:'帮扶认领'});
		plus.webview.show(helpNews, "slide-in-right", "350ms", function() {}, false);
	});
	$("#sign").on("tap",function(){//签到
		var sign = plus.webview.create("../notice/notice.html", "../notice/notice.html", {scrollIndicator:'none'},{type:'child'});
		plus.webview.show(sign, "slide-in-right", "350ms", function() {}, false);
	});
}

//获取新闻头条
function getBanner(){
	mui.ajax(ctx+"mobile/common/getBanner",{
		dataType:'json',//服务器返回json格式数据
		type:'post',//HTTP请求类型
		timeout:10000,//超时时间设置为10秒；	              
		success:function(data){
	       	if(data&&data.success){
	       		var html = "";
	       		var pointhtml = "";
	       		if(data.data){
	       			var bannerList = data.data;
	       			var first="";//第一张
	       			var last="";//最后一张
	       			$.each(bannerList,function(i,d){
	       				if(i==0){//第一张
	       					first = first + '<div class="mui-slider-item contentLi" data-id="'+d.id+'">';
							first = first + '<a href="javascript:void(0);"><img src="'+ctx+d.img+'" style="width:100%;height:230px;"></a>';
							first = first + '</div>';
							pointhtml = pointhtml +'<div class="mui-indicator mui-active"></div>';
	       				}else{
	       					pointhtml = pointhtml +'<div class="mui-indicator"></div>';
	       				}
	       				if(i==bannerList.length-1){//最后一张
	       					last = last + '<div class="mui-slider-item bannerLi" data-id="'+d.id+'">';
							last = last + '<a href="javascript:void(0);"><img src="'+ctx+d.img+'" style="width:100%;height:230px;"></a>';
							last = last + '</div>';
	       				}
	       				html = html + '<div class="mui-slider-item bannerLi" data-id="'+d.id+'">';
						html = html + '<a href="javascript:void(0);"><img src="'+ctx+d.img+'" style="width:100%;height:230px;"></a>';
						html = html + '</div>';
	       			});
	       			//循环完成之后，组装html
	       			html = last + html + first;
	       			$("#banner").html(html);
	       			$("#pointList").html(pointhtml);
	       			var gallery = mui('.mui-slider');
			        gallery.slider({
				  	    interval:3000//自动轮播周期，若为0则不自动播放，默认为0；
				    });
				    $(".bannerLi").on("tap",function(){//详情页面
						var content = plus.webview.create("../content/content.html", "../content/content.html", {scrollIndicator:'none'},{type:'6',dataId:$(this).attr("data-id")});
						//	显示新页面
						plus.webview.show(content, "slide-in-right", "350ms", function() {}, false);
					});
	       		}
	      	}else{
	      		alert('服务器异常链接失败!');
	      	}
		},
		error:function(xhr,type,errorThrown){
			alert('服务器异常链接失败!');
		}
	});
}

function getImportantNews(){
	mui.ajax(ctx+"mobile/common/getContentList?type=6",{
		dataType:'json',//服务器返回json格式数据
		type:'post',//HTTP请求类型
		timeout:10000,//超时时间设置为10秒；	              
		success:function(data){
	       	if(data&&data.success){
	       		var html = "";
	       		if(data.data){
	       			var list = data.data;
	       			$.each(list,function(i,d){
	       				if(!d.img){
	       					d.img="../../img/app/defaultImg.png"
	       				}else{
	       					d.img=ctx+d.img;
	       				}
	       				html = html + '<li class="mui-table-view-cell mui-media contentLi" data-id="'+d.id+'">';
							html = html + '<a href="javascript:;">';
								html = html + '<img class="mui-media-object mui-pull-left" src="'+d.img+'">';
								html = html + '<div class="mui-media-body">';
									html = html + d.title;
									html = html + '<p class="mui-ellipsis">'+(d.text_content?d.text_content:'')+'</p>';
								html = html + '</div>';
							html = html + '</a>';
						html = html + '</li>';
	       			});
	       			$("#importantNews").html(html);
	       			$(".contentLi").on("tap",function(){//详情页面
						var content = plus.webview.create("../content/content.html", "../content/content.html", {scrollIndicator:'none'},{type:'6',dataId:$(this).attr("data-id")});
						//	显示新页面
						plus.webview.show(content, "slide-in-right", "350ms", function() {}, false);
					});
	       		}
	      	}else{
	      		alert('服务器异常链接失败!');
	      	}
		},
		error:function(xhr,type,errorThrown){
			alert('服务器异常链接失败!');
		}
	});
}
